<template>
  <div
    class="receipt-order-edit-wrapper app-container"
    style="margin-bottom: 60px"
    v-loading="loading"
  >
    <el-card header="创建QMS请验单">
      <el-row :gutter="10">
        <el-form
          ref="elForm"
          :model="headerList"
          :rules="rules"
          size="small"
          label-width="130px"
        >
          <!-- <el-col :span="24">
            <el-form-item label="入库单表头主键" prop="cgeneralhid">
              <el-input v-model="headerList.cgeneralhid" placeholder="请输入入库单表头主键" clearable
                :style="{ width: '100%' }"></el-input>
            </el-form-item>
          </el-col> -->

          <el-table :data="baseInfoList" border label-position="top">
            <el-table-column label="单据号" align="center">
              <template #default="{ row }">{{ row.vbillcode }}</template>
            </el-table-column>
            <el-table-column label="表体主键" align="center">
              <template #default="{ row }">{{ row.cgeneralbid }}</template>
            </el-table-column>
            <el-table-column label="物料信息" align="center" width="300">
              <template #default="{ row }">
                <div>物料名称：{{ row.productName }}</div>
                <div>GMP码：{{ row.productGmp }}</div>
                <div>物料规格：{{ row.productSpec }}</div>
              </template>
            </el-table-column>
            <el-table-column label="批号信息" align="center">
              <template #default="{ row }">
                <div>供应商批号：{{ row.originalBatch }}</div>
                <div>自制物料批号：{{ row.batchNum }}</div>
              </template>
            </el-table-column>
            <el-table-column label="厂商批号" align="center">
              <template #default="{ row }">{{ row.originalBatch }}</template>
            </el-table-column>

            <el-table-column label="有效期至" align="center">
              <template #default="{ row }">{{
                formatDate(row.validityDate)
              }}</template>
            </el-table-column>
            <el-table-column label="复验期至" align="center">
              <template #default="{ row }">{{
                formatDate(
                  row.reinspectDate === "1900-01-01 00:00:00"
                    ? null
                    : row.reinspectDate
                )
              }}</template>
            </el-table-column>

            <el-table-column label="有效期(数字)" align="center">
              <template #default="{ row }">{{ row.validityStr }}</template>
            </el-table-column>
            <el-table-column label="有效期单位" align="center">
              <template #default="{ row }">
                {{
                  row.qualityUnit == 0
                    ? "年"
                    : row.qualityUnit == 1
                    ? "月"
                    : row.qualityUnit == 2
                    ? "日"
                    : ""
                }}
              </template>
            </el-table-column>
            <el-table-column label="复检期" align="center">
              <template #default="{ row }">{{ row.reinspectStr }}</template>
            </el-table-column>

            <el-table-column label="操作" align="center" width="80">
              <template #default="{ row }">
                <!-- <div v-if="row.stu_state == 4" style="margin: 5px;">
                  <el-button link size="small" type="primary" plain @click="handleAdd(row)">请验</el-button>
                </div> -->
                <div style="margin: 5px">
                  <el-button
                    link
                    size="small"
                    type="primary"
                    plain
                    @click="handleAdd(row)"
                    >请验</el-button
                  >
                </div>
              </template>
            </el-table-column>
          </el-table>
        </el-form>
      </el-row>
    </el-card>
    <el-dialog
      title="请验信息单"
      :visible.sync="dialogFormVisible"
      append-to-body
      width="80%"
    >
      <div class="form-container">
        <el-form :model="detailsList" :rules="rules" label-width="120px">
          <!-- 基本信息头 -->
          <el-card shadow="never" class="card-section">
            <span slot="header" class="card-header">基本信息头</span>
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="单据号" prop="vbillcode">
                  <el-input
                    v-model="detailsList.vbillcode"
                    placeholder="请输入单据号"
                    clearable
                  ></el-input>
                </el-form-item>
              </el-col>
              <!-- <el-col :span="8">
                <el-form-item label="表体主键" prop="cgeneralbid">
                  <el-input v-model="detailsList.cgeneralbid" placeholder="请输入单据号" clearable></el-input>
                </el-form-item>
              </el-col> -->
              <el-col :span="8">
                <el-form-item label="物料名称" prop="productName">
                  <el-input
                    v-model="detailsList.productName"
                    placeholder="请输入物料名称"
                    clearable
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="物料规格" prop="productSpec">
                  <el-input
                    v-model="detailsList.productSpec"
                    placeholder="请输入货品规格"
                    clearable
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="GMP码" prop="productGmp">
                  <el-input
                    v-model="detailsList.productGmp"
                    placeholder="请输入物料代码"
                    clearable
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="厂商批号" prop="originalBatch">
                  <el-input
                    v-model="detailsList.originalBatch"
                    placeholder="请输入批号"
                    clearable
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="内部物料批号" prop="batchNum">
                  <el-input
                    v-model="detailsList.batchNum"
                    placeholder="请输入批号"
                    clearable
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="包装规格" prop="productPackSpec">
                  <el-input
                    v-model="detailsList.productPackSpec"
                    placeholder="请输入包装规格"
                    clearable
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="总数量" prop="pleaseCheckQuantity">
                  <div class="input-with-select">
                    <!-- <el-input
                      v-model="detailsList.pleaseCheckQuantity"
                      placeholder="请输入总数量"
                      clearable
                      style="width: 70%"
                    ></el-input> -->
                    <el-input-number
                      v-model="detailsList.pleaseCheckQuantity"
                      placeholder="请输入总数量"
                      clearable
                      style="width: 70%"
                      :min="0"
                      :max="9999999999"
                      :step="1"
                      controls-position="right"
                    ></el-input-number>
                    <el-select
                      v-model="detailsList.pleaseCheckQuantityUnitName"
                      placeholder="单位"
                      style="width: 30%"
                    >
                      <el-option
                        v-for="item in pqOptions"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                      >
                      </el-option>
                    </el-select>
                  </div>
                </el-form-item>
              </el-col>

              <el-col :span="8">
                <!-- <el-form-item label="包装件数" prop="grossPiece">
                  <el-input v-model="detailsList.grossPiece" placeholder="请输入包装件数" clearable></el-input>
                </el-form-item> -->
                <el-form-item label="包装件数" prop="grossPiece">
                  <el-input-number
                    v-model="detailsList.grossPiece"
                    :min="0"
                    :max="9999999999"
                    :step="1"
                    placeholder="请输入包装件数"
                    controls-position="right"
                  ></el-input-number>
                </el-form-item>
              </el-col>
            </el-row>

            <el-row :gutter="20">
              <el-col :span="10">
                <el-form-item label="请验目的" prop="checkPurpose">
                  <el-radio-group
                    v-model="detailsList.checkPurpose"
                    size="small"
                  >
                    <el-radio-button label="进厂检验"></el-radio-button>
                    <el-radio-button label="复检"></el-radio-button>
                    <el-radio-button label="接近有效期"></el-radio-button>
                    <el-radio-button label="其他"></el-radio-button>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
          </el-card>

          <!-- 生产企业 -->
          <el-card shadow="never" class="card-section">
            <span slot="header" class="card-header">生产企业</span>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="生产企业" prop="manufacturerName">
                  <el-input
                    v-model="detailsList.manufacturerName"
                    placeholder="请输入生产企业"
                    clearable
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="生产日期" prop="productionDate">
                  <el-date-picker
                    v-model="detailsList.productionDate"
                    type="datetime"
                    format="yyyy-MM-dd HH:mm:ss"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    placeholder="选择日期"
                    clearable
                    :style="{ width: '100%' }"
                  >
                  </el-date-picker>
                </el-form-item>
              </el-col>
            </el-row>
            <!-- 日期选择部分 --><!-- 期限输入部分 -->
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="类型选择">
                  <el-select
                    v-model="dateType"
                    placeholder="选择类型"
                    @change="handleTypeChange"
                    clearable
                  >
                    <el-option
                      label="有效期至"
                      value="validityDate"
                    ></el-option>
                    <el-option
                      label="复验期至"
                      value="reinspectDate"
                    ></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item
                  :label="dateType === 'validityDate' ? '有效期至' : '复验期至'"
                >
                  <el-date-picker
                    v-model="detailsList[dateType]"
                    type="datetime"
                    format="yyyy-MM-dd HH:mm:ss"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    placeholder="选择日期"
                    clearable
                    :style="{ width: '100%' }"
                    @change="handleDateChange(dateType)"
                  ></el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="类型选择">
                  <el-select
                    v-model="strType"
                    placeholder="选择类型"
                    @change="handleTypeChange"
                    clearable
                    :disabled="true"
                  >
                    <el-option label="有效期" value="validityStr"></el-option>
                    <el-option label="复验期" value="reinspectStr"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item
                  :label="strType === 'validityStr' ? '有效期' : '复验期'"
                >
                  <el-input
                    v-model="detailsList[strType]"
                    placeholder="请输入期限"
                    clearable
                    @input="handleStrChange(strType)"
                    style="width: 80%"
                  >
                  </el-input>
                  <el-select
                    v-model="detailsList.qualityUnit"
                    placeholder="单位"
                    style="width: 20%"
                  >
                    <el-option
                      v-for="item in puOptions"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </el-card>

          <!-- 基本信息尾 -->
          <el-card shadow="never" class="card-section">
            <span slot="header" class="card-header">基本信息尾</span>
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="是否全检" prop="allTest">
                  <el-radio-group v-model="detailsList.allTest">
                    <el-radio-button label="是"></el-radio-button>
                    <el-radio-button label="否"></el-radio-button>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="初验结论" prop="firstVerdict">
                  <el-radio-group v-model="detailsList.firstVerdict">
                    <el-radio-button label="符合规定"></el-radio-button>
                    <el-radio-button label="不符合规定"></el-radio-button>
                    <el-radio-button label="其他"></el-radio-button>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="物料进厂日期" prop="comeDate">
                  <el-date-picker
                    v-model="detailsList.comeDate"
                    type="datetime"
                    format="yyyy-MM-dd HH:mm:ss"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    placeholder="选择日期"
                    clearable
                    :style="{ width: '100%' }"
                  >
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <!-- <el-col :span="8">
                <el-form-item label="物料接收人" prop="">
                  <el-input v-model="detailsList.receiver" placeholder="请输入物料接收人" clearable></el-input>
                </el-form-item>
              </el-col> -->
            </el-row>
            <!-- <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="请验部门" prop="">
                  <el-input v-model="detailsList.inspectionDept" placeholder="请输入请验部门" clearable></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="请验人" prop="">
                  <el-input v-model="detailsList.createUserName" placeholder="请输入请验人" clearable></el-input>
                </el-form-item>
              </el-col>
            </el-row> -->
            <el-row :gutter="20">
              <!-- <el-col :span="8">
                <el-form-item label="请验日期" prop="">
                  <el-date-picker v-model="detailsList.inspectionDate" type="datetime" format="yyyy-MM-dd HH:mm:ss"
                    value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期" clearable :style="{ width: '100%' }">
                  </el-date-picker>
                </el-form-item>
              </el-col> -->
              <el-col :span="8">
                <el-form-item label="备注" prop="remark">
                  <el-input
                    v-model="detailsList.remark"
                    placeholder="请输入备注"
                    clearable
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-card>
        </el-form>
      </div>

      <el-form label-width="10px" :rules="rules">
        <el-form-item
          size="large"
          style="margin-top: 20px; display: flex; justify-content: flex-end"
        >
          <el-button type="primary" @click="createQmsCreateQmsList"
            >提交请验</el-button
          >
          <!-- <el-button @click="resetForm">重置</el-button> -->
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
// 获取明细基础数据接口
import { getQmsGetBaseInfo } from "@/api/public.js";
// 获取创建QMS请验单接口
import { createQmsCreateQms } from "@/api/public.js";

export default {
  data() {
    return {
      loading: false, // 控制加载状态
      selectedRow: null, // 当前选中的表格行
      tableRowChecked: [], // 用于记录每行的选中状态
      nccList: [], // NCC仓库信息
      nccStatusList: [], // NCC库存状态信息
      headerList: {
        cgeneralhid: "", // 入库单表头主键
      },
      baseInfoList: [], // 商品明细信息
      // 默认选中“有效期至”和“有效期”
      dateType: "validityDate",
      strType: "validityStr",
      detailsList: {
        vbillcode: "",
        productName: "",
        productGmp: "",
        productSpec: "",
        originalBatch: "",
        batchNum: "",
        productPackSpec: "",
        pleaseCheckQuantity: "",
        pleaseCheckQuantityUnitName: "",
        grossPiece: "",
        checkPurpose: "",
        manufacturerName: "",
        productionDate: "",
        validityDate: null, // 有效期至的日期
        reinspectDate: null, // 复验期至的日期
        validityStr: "", // 有效期的字符串
        reinspectStr: "", // 复验期的字符串
        qualityUnit: "", // 有效期的单位
        allTest: "",
        firstVerdict: "",
        comeDate: "",
        receiver: "", // 物料接收人
        inspectionDept: "", // 请验部门
        createUserName: "",
        inspectionDate: "", // 请验日期
        remark: "",
        modeType: "0",
      },
      dialogFormVisible: false,
      rules: {
        cgeneralhid: [
          { required: true, message: "请输入入库单表头主键", trigger: "blur" },
        ],
        // 以下为请验详情表单的表单校验
        vbillcode: [
          { required: true, message: "请输入单据号", trigger: "blur" },
        ],
        productName: [
          { required: true, message: "请输入物料名称", trigger: "blur" },
        ],
        productGmp: [
          { required: true, message: "请输入GMP码", trigger: "blur" },
        ],
        productSpec: [
          { required: true, message: "请输入物料规格", trigger: "blur" },
        ],
        originalBatch: [
          { required: true, message: "请输入厂商批号", trigger: "blur" },
        ],
        batchNum: [
          { required: true, message: "请输入内部物料批号", trigger: "blur" },
        ],
        productPackSpec: [
          { required: true, message: "请输入包装规格", trigger: "blur" },
        ],
        pleaseCheckQuantity: [
          { required: true, message: "请输入总数量", trigger: "blur" },
        ],
        grossPiece: [
          { required: true, message: "请输入包装件数", trigger: "blur" },
        ],
        checkPurpose: [
          { required: true, message: "请选择请验目的", trigger: "change" },
        ],
        manufacturerName: [
          { required: true, message: "请输入生产企业", trigger: "blur" },
        ],
        productionDate: [
          { required: true, message: "请选择生产日期", trigger: "change" },
        ],
        dateType: [
          { required: true, message: "请选择类型", trigger: "change" },
        ],
        strType: [{ required: true, message: "请选择类型", trigger: "change" }],
        allTest: [
          { required: true, message: "请选择是否全检", trigger: "change" },
        ],
        firstVerdict: [
          { required: true, message: "请选择初验结论", trigger: "change" },
        ],
        comeDate: [
          { required: true, message: "请选择物料进厂日期", trigger: "change" },
        ],
        // remark: [
        //   { required: true, message: '请输入备注', trigger: 'blur' }
        // ]
      },
      isValidityChanged: false,
      isReinspectChanged: false,

      pqOptions: [
        { value: "盒", label: "盒" },
        { value: "支", label: "支" },
        { value: "个", label: "个" },
        { value: "瓶", label: "瓶" },
        { value: "件", label: "件" },
        { value: "条", label: "条" },
        { value: "张", label: "张" },
        { value: "片", label: "片" },
        { value: "粒", label: "粒" },
        { value: "袋", label: "袋" },
        { value: "mg", label: "mg" },
        { value: "桶", label: "桶" },
        { value: "kg", label: "kg" },
        { value: "g", label: "g" },
        { value: "万粒", label: "万粒" },
        { value: "ml", label: "ml" },
        { value: "m", label: "m" },
        { value: "套", label: "套" },
        { value: "根", label: "根" },
        { value: "只", label: "只" },
        { value: "万片", label: "万片" },
        { value: "万袋", label: "万袋" },
        { value: "L", label: "L" },
        { value: "卷", label: "卷" },
        { value: "万支", label: "万支" },
        { value: "板", label: "板" },
        { value: "双", label: "双" },
        { value: "听", label: "听" },
        { value: "厘米", label: "厘米" },
        { value: "cm", label: "cm" },
        { value: "毫米", label: "毫米" },
        { value: "mm", label: "mm" },
      ],
      puOptions: [
        { value: "0", label: "年" },
        { value: "1", label: "月" },
        { value: "2", label: "日" },
      ],
    };
  },
  watch: {
    // 监听日期类型的变化，并同步更新期限类型
    dateType(newValue) {
      if (newValue === "validityDate") {
        this.strType = "validityStr";
      } else if (newValue === "reinspectDate") {
        this.strType = "reinspectStr";
      }
    },
    // 监听期限类型的变化，并同步更新日期类型
    strType(newValue) {
      if (newValue === "validityStr") {
        this.dateType = "validityDate";
      } else if (newValue === "reinspectStr") {
        this.dateType = "reinspectDate";
      }
    },
  },
  created() {
    // 获取路由传递的参数
    this.vbillcode = this.$route.query.vbillcode;
    this.cgeneralbid = this.$route.query.cgeneralbid;

    if (!this.vbillcode) {
      this.$message.error("未接收到订单编号，请返回重试！");
    }
    if (!this.cgeneralbid) {
      this.$message.error("cgeneralbid 参数未传递或为空！");
    }
  },
  mounted() {
    this.queryQmsGetBaseInfoList(); // 查询获取明细基础数据列表
    // 手动触发默认值的处理
    this.handleDateChange(this.dateType);
    this.handleStrChange(this.strType);
  },
  methods: {
    // 格式化时间
    formatDate(date) {
      if (!date) return ""; // 如果 `date` 为空或 `null`，返回占位符
      return this.$dayjs(date).isValid()
        ? this.$dayjs(date).format("YYYY-MM-DD")
        : "-";
    },

    // 当任意一个类型选择改变时，确保两个下拉框的值一一对应
    handleTypeChange() {
      if (this.dateType === "validityDate" && this.strType !== "validityStr") {
        this.strType = "validityStr"; // 确保期限类型与日期类型对应
      } else if (
        this.dateType === "reinspectDate" &&
        this.strType !== "reinspectStr"
      ) {
        this.strType = "reinspectStr"; // 确保期限类型与日期类型对应
      }
    },
    handleDateChange(type) {
      if (type === "validityDate") {
        this.isValiditySet = true;
        this.isReinspectSet = false;
      } else {
        this.isValiditySet = false;
        this.isReinspectSet = true;
      }
      // 确保日期字段是有效的日期对象
      if (this.detailsList[type]) {
        if (typeof this.detailsList[type] === "string") {
          this.detailsList[type] = new Date(this.detailsList[type]);
        }
      }
    },
    handleStrChange(type) {
      if (type === "validityStr") {
        this.isValiditySet = true;
        this.isReinspectSet = false;
      } else {
        this.isValiditySet = false;
        this.isReinspectSet = true;
      }
    },

    // 点击 请验 按钮，同步表格的的数据到表单
    handleAdd(row) {
      console.log("handleAdd(row)=", row);
      this.dialogFormVisible = true;
      // 将选中行的数据传递到弹出框的detailsList中

      // 获取明细基础数据接口getQmsGetBaseInfo 请求到的数据
      // handleAdd(row) ={
      //   batchNum: "BC125-2501"
      //   cgeneralbid: "1001ZZ10000000ABNF7Z"
      //   manufacturerName: "华北制药河北华民药业有限责任公司(受托生产企业)"
      //   originalBatch: "1234"
      //   productGmp: "BC125"
      //   productName: "药用喷雾剂定量泵（鼻腔推钮）"
      //   productSpec: "成人型"
      //   productionDate: "2025-03-01 00:00:00.0"
      //   qualityUnit: "1"
      //   reinspectDate: ""
      //   reinspectStr: null
      //   validityDate: "2026-03-31 00:00:00.0"
      //   validityStr: "36"
      //   vbillcode: "CR2503030854"
      // }

      this.detailsList.batchNum = row.batchNum;
      // cgeneralbid(表体主键)
      this.detailsList.manufacturerName = row.manufacturerName;
      this.detailsList.originalBatch = row.originalBatch;
      this.detailsList.productGmp = row.productGmp;
      this.detailsList.productName = row.productName;
      this.detailsList.productSpec = row.productSpec;
      this.detailsList.productionDate = row.productionDate;
      this.detailsList.qualityUnit = row.qualityUnit;
      this.detailsList.reinspectDate = row.reinspectDate;
      this.detailsList.reinspectStr = row.reinspectStr;
      this.detailsList.validityDate = row.validityDate;
      this.detailsList.validityStr = row.validityStr;
      this.detailsList.vbillcode = row.vbillcode;

      // this.detailsList.productPackSpec = row.productPackSpec;
      // this.detailsList.pleaseCheckQuantity = row.pleaseCheckQuantity;
      // this.detailsList.pleaseCheckQuantityUnitName = row.pleaseCheckQuantityUnitName;
      // this.detailsList.grossPiece = row.grossPiece;
      // this.detailsList.checkPurpose = row.checkPurpose;
      // this.detailsList.allTest = row.firstVerdict;
      // this.detailsList.comeDate = row.comeDate;
      // this.detailsList.receiver = row.receiver;
      // this.detailsList.inspectionDept = row.inspectionDept;
      // this.detailsList.createUserName = row.createUserName;
      // this.detailsList.inspectionDate = row.inspectionDate;
      // this.detailsList.remark = row.remark;
    },

    /**
     * 创建QMS请验单
     */
    createQmsCreateQmsList() {
      // 开启加载状态提示
      this.loading = true;
      if (!this.isValiditySet && !this.isReinspectSet) {
        this.loading = false;
        this.$message.error(
          "请填写有效期至和有效期 或者 复验期至和复验期 其中一组"
        );
        return;
      }
      if (this.isValiditySet && this.isReinspectSet) {
        this.loading = false;
        this.$message.error(
          "只能填写有效期至和有效期 或者 复验期至和复验期 其中一组"
        );
        return;
      }
      const detailsData = {
        cgeneralbid: this.cgeneralbid,
        vbillcode: this.detailsList.vbillcode,
        productName: this.detailsList.productName,
        productGmp: this.detailsList.productGmp,
        productSpec: this.detailsList.productSpec,
        originalBatch: this.detailsList.originalBatch,
        batchNum: this.detailsList.batchNum,
        productPackSpec: this.detailsList.productPackSpec,
        pleaseCheckQuantity: this.detailsList.pleaseCheckQuantity,
        pleaseCheckQuantityUnitName:
          this.detailsList.pleaseCheckQuantityUnitName,
        grossPiece: this.detailsList.grossPiece,
        checkPurpose: this.detailsList.checkPurpose,
        manufacturerName: this.detailsList.manufacturerName,
        productionDate: this.detailsList.productionDate,
        validityDate: this.isValiditySet ? this.detailsList.validityDate : null,
        reinspectDate: this.isReinspectSet
          ? this.detailsList.reinspectDate
          : null,
        validityStr: this.isValiditySet ? this.detailsList.validityStr : null,
        reinspectStr: this.isReinspectSet
          ? this.detailsList.reinspectStr
          : null,
        allTest: this.detailsList.allTest,
        firstVerdict: this.detailsList.firstVerdict,
        comeDate: this.detailsList.comeDate,
        // receiver: this.detailsList.receiver,
        // inspectionDept: this.detailsList.inspectionDept,
        // createUserName: this.detailsList.createUserName,
        // inspectionDate: this.detailsList.inspectionDate,
        remark: this.detailsList.remark,
        modeType: this.detailsList.modeType,
      };
      const combinedDat = { detailsData };
      console.log("QMS请验，combinedDat数据：", combinedDat);

      createQmsCreateQms(combinedDat)
        .then((response) => {
          console.log("接口请求成功，返回response数据：", response);

          this.loading = false;

          if (response.code === 200) {
            this.$message.success(response.msg);
            this.dialogFormVisible = false;
            this.$tab.closePage(); // 关闭当前页面的标签
          } else {
            // this.$message.error('提交失败，请稍后再试');
            this.$message.error(response.msg);
          }
        })
        .catch((error) => {
          this.loading = false;
          console.log("接口请求出错:", error);
        });
    },

    /**
     * 查询获取明细基础数据列表
     */
    queryQmsGetBaseInfoList() {
      this.loading = true;
      const params = {
        vbillcode: this.vbillcode,
        cgeneralbid: this.cgeneralbid,
      };
      console.log("params监控=", params);
      getQmsGetBaseInfo(params)
        .then((response) => {
          console.log("接口请求成功，返回response数据：", response);
          // 假设接口返回的数据数组中第一个元素包含了我们需要的header和details等信息，先获取这个元素
          this.baseInfoList = [response.data];
          console.log("接口请求成功，返回数据：", response.data);
          this.loading = false;
          // 关闭加载状态提示，数据获取完成
        })
        .catch(() => {
          this.loading = false;
          // this.$message.error('采购订单数据加载失败');
          this.$message({
            message: response.msg, // 显示返回的提示信息
            type: "error",
          });
        });
    },

    // resetForm() {
    //   this.$refs.elForm.resetFields();
    // }
  },
};
</script>

<style scoped>
.form-container {
  margin: 20px;
}

.card-section {
  margin-bottom: 20px;
}

.card-header {
  font-size: 16px;
  font-weight: bold;
}

.input-with-select {
  display: flex;
  align-items: center;
}

.input-with-select .el-input,
.input-with-select .el-select {
  margin-right: 3px;
}
</style>